From 90562ffd561be71d472fa293ae74612d55d2016a Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Thu, 18 Aug 2005 19:21:09 +0000 Subject: [PATCH] Get rid of xenbus_uuid_to_domid - get the frontend id from the node. We don't want to parse paths we read out of the store to _construct_ other paths and tie down the store layout for no good reason. Also require the frontend path to exist and be valid before creating the device. Signed-off-by: Christian Limpach --- .../drivers/xen/xenbus/xenbus_probe.c | 60 +++++++++---------- linux-2.6-xen-sparse/include/asm-xen/xenbus.h | 3 - 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c index 06b33fd645..cfdd92fcdd 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c @@ -109,47 +109,41 @@ static struct xen_bus_type xenbus_frontend = { }, }; -/* For backends, does lookup on uuid (up to /). Returns domid, or -errno. */ -int xenbus_uuid_to_domid(const char *uuid) -{ - int err, domid, len; - char path[strlen("/domain/") + 50]; - - len = strcspn(uuid, "/"); - if (snprintf(path, sizeof(path), "/domain/%.*s", len, uuid) - >= sizeof(path)) - return -ENOSPC; - err = xenbus_scanf(path, "id", "%i", &domid); - if (err != 1) - return err; - return domid; -} - /* backend/// => -- */ static int backend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename) { - unsigned int typelen, uuidlen; - int domid; - const char *p; + int domid, err; + const char *devid, *type, *frontend; + unsigned int typelen; - nodename = strchr(nodename, '/'); - if (!nodename) - return -EINVAL; - nodename++; - typelen = strcspn(nodename, "/"); - if (!typelen || nodename[typelen] != '/') + type = strchr(nodename, '/'); + if (!type) return -EINVAL; - p = nodename + typelen + 1; - uuidlen = strcspn(p, "/"); - if (!uuidlen || p[uuidlen] != '/') + type++; + typelen = strcspn(type, "/"); + if (!typelen || type[typelen] != '/') return -EINVAL; - domid = xenbus_uuid_to_domid(p); - if (domid < 0) - return domid; - p += uuidlen + 1; + + devid = strrchr(nodename, '/') + 1; + + err = xenbus_gather(nodename, "frontend-id", "%i", &domid, + "frontend", NULL, &frontend, + NULL); + if (err) + return err; + if (strlen(frontend) == 0) + err = -ERANGE; + + if (!err && !xenbus_exists(frontend, "")) + err = -ENOENT; + + if (err) { + kfree(frontend); + return err; + } if (snprintf(bus_id, BUS_ID_SIZE, - "%.*s-%i-%s", typelen, nodename, domid, p) >= BUS_ID_SIZE) + "%.*s-%i-%s", typelen, type, domid, devid) >= BUS_ID_SIZE) return -ENOSPC; return 0; } diff --git a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h index 25b2d1ce80..685b5d7a3e 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h @@ -126,9 +126,6 @@ int register_xenbus_watch(struct xenbus_watch *watch); void unregister_xenbus_watch(struct xenbus_watch *watch); void reregister_xenbus_watches(void); -/* For backends, does lookup on uuid (up to /). Returns domid, or -errno. */ -int xenbus_uuid_to_domid(const char *uuid); - /* Called from xen core code. */ void xenbus_suspend(void); void xenbus_resume(void); -- 2.30.2